package oving9;

import java.util.ArrayList;
import java.util.List;

public abstract class ObservableList{
	ArrayList<ListListener> listeners= new ArrayList<ListListener>();
	
	public void addListListener(ListListener ll){
		if(ll!=null){
			if(!listeners.contains(ll)){
				listeners.add(ll);
			}
		}
	}
	public void removeListListener(ListListener ll){
		if(ll!=null){
			if(listeners.contains(ll)){
				listeners.remove(ll);
			}
		}
	}
	protected void fireListChanged(int arg1, int arg2){
		for (ListListener ll: listeners) {
			ll.listChanged(this, arg1, arg2);
		}
	}
	protected abstract List getList();
	
	public int size(){
		return getList().size();
	}
	protected void addElement(int index, Object element){		
			getList().add(index, element);
			fireListChanged(index,getList().size()-1);
		
	}
	protected void removeElement(int index){
		getList().remove(index);
		fireListChanged(index,getList().size());

	}
	
}
